package com.yztc.ui.details;

import com.yztc.bean.details.DetailsBean;
import com.yztc.http.RetrofitService;
import com.yztc.utils.HttpHelper;

import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by My on 2016/10/10.
 */
public class DetailsModel implements DetailsConstact.IDetailsModel{
    @Override
    public void toLoadData(String baseUrl, int productId, final OnDataListener onDataListener) {
        Observable observable = HttpHelper
                .getInstance()
                .getRetrofit(baseUrl)
                .create(RetrofitService.class)
                .getDetailsBean(productId);
        observable.observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<DetailsBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable throwable) {
                       onDataListener.failGetData(throwable);
                    }

                    @Override
                    public void onNext(DetailsBean detailsBean) {
                       onDataListener.successGetData(detailsBean);
                    }
                });


    }

   public interface OnDataListener{
        public void successGetData(DetailsBean detailsBean);
        public void failGetData(Throwable throwable);
    }
}
